package com.qf.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.qf.mapper.DtsPermissionMapper;
import com.qf.pojo.DtsPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author fy
 * @version V1.0
 * @Project workspace
 * @Package com.qf.service
 * @Description:
 * @Date 2022/6/20 22:48
 */
@Service
public class PermissionServiceImpl implements PermissionService {
    @Autowired
    private DtsPermissionMapper dtsPermissionMapper;
    @Override
    public Set<String> queryPermissionByRoleIds(Integer[] ids) {

        //如果ids为空，返回空的set集合
        if (ids==null||ids.length==0){
            return new HashSet<String>();
        }
        //创建并设置查询条件
        QueryWrapper <DtsPermission> queryWrapper = new QueryWrapper();
        queryWrapper.in("role_id", ids);
        queryWrapper.eq("deleted", false);
        //查询并返回结果
        List<DtsPermission> list = dtsPermissionMapper.selectList(queryWrapper);
        Set<String> permSet = new HashSet<>();
        if (list!=null){
            for (DtsPermission dtsPermission : list) {
                permSet.add(dtsPermission.getPermission());
            }
        }
        return permSet;
    }
}
